package com.fk.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.fk.entity.XinWenXiangQing;
import com.fk.uitl.DBManager;

public class XinWenXiangQingDaoImpl {
	//新闻详情
		public List<XinWenXiangQing> getXinWenXiangQingList(int cId){
			List<XinWenXiangQing> xwxqList=new ArrayList<XinWenXiangQing>();
			
			Connection conn=DBManager.getConnection();
			Statement st=null;
			ResultSet rs=null;
			
			try {
				st=conn.createStatement();
				rs=st.executeQuery("select * from xinwenxiangqing where xinWenFenLeiId="+cId);
				while(rs.next()){
					int xinWenNeiRongId=rs.getInt("xinWenNeiRongId");
					String xinWenBiaoTi=rs.getString("xinWenBiaoTi");
					String xinWenNeiRong=rs.getString("xinWenNeiRong");
					int xinWenFenLeiId=rs.getInt("xinWenFenLeiId");
					XinWenXiangQing xwxq=new XinWenXiangQing(xinWenNeiRongId, xinWenBiaoTi, xinWenNeiRong, xinWenFenLeiId);
					xwxqList.add(xwxq);
				}
				return xwxqList;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			} finally {
				DBManager.closeAll(conn, st, rs);
			}
		}
		
		//新闻详情咨讯
		public List<XinWenXiangQing> getxwxqList(int gId){
			List<XinWenXiangQing> NewsInforMationList=new ArrayList<XinWenXiangQing>();
			
			Connection conn=DBManager.getConnection();
			Statement st=null;
			ResultSet rs=null;
			
			try {
				st=conn.createStatement();
				rs=st.executeQuery("select * from xinwenxiangqing where xinWenNeiRongId="+gId);
				while(rs.next()){
					int xinWenNeiRongId=rs.getInt("xinWenNeiRongId");
					String xinWenBiaoTi=rs.getString("xinWenBiaoTi");
					String xinWenNeiRong=rs.getString("xinWenNeiRong");
					XinWenXiangQing xwxq=new XinWenXiangQing(xinWenNeiRongId, xinWenBiaoTi, xinWenNeiRong);
					NewsInforMationList.add(xwxq);
				}
				return NewsInforMationList;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			} finally {
				DBManager.closeAll(conn, st, rs);
			}
		}
		
		//首页新闻资讯
		public List<XinWenXiangQing> getsyxwList(){
			List<XinWenXiangQing> syxwList=new ArrayList<XinWenXiangQing>();
			
			Connection conn=DBManager.getConnection();
			Statement st=null;
			ResultSet rs=null;
			
			try {
				st=conn.createStatement();
				rs=st.executeQuery("select * from xinwenxiangqing order by rand() limit 4");
				while(rs.next()){
					int xinWenNeiRongId=rs.getInt("xinWenNeiRongId");
					String xinWenBiaoTi=rs.getString("xinWenBiaoTi");
					String xinWenNeiRong=rs.getString("xinWenNeiRong");
					XinWenXiangQing xwxq=new XinWenXiangQing(xinWenNeiRongId, xinWenBiaoTi, xinWenNeiRong);
					syxwList.add(xwxq);
				}
				return syxwList;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			} finally {
				DBManager.closeAll(conn, st, rs);
			}
		}
		
		//首页新闻资讯图片下的新闻
		public List<XinWenXiangQing> getsyxwTuPianList(){
			List<XinWenXiangQing> xwtpList=new ArrayList<XinWenXiangQing>();
			
			Connection conn=DBManager.getConnection();
			Statement st=null;
			ResultSet rs=null;
			
			try {
				st=conn.createStatement();
				rs=st.executeQuery("select * from xinwenxiangqing order by rand() limit 1");
				while(rs.next()){
					int xinWenNeiRongId=rs.getInt("xinWenNeiRongId");
					String xinWenBiaoTi=rs.getString("xinWenBiaoTi");
					String xinWenNeiRong=rs.getString("xinWenNeiRong");
					XinWenXiangQing xwxq=new XinWenXiangQing(xinWenNeiRongId, xinWenBiaoTi, xinWenNeiRong);
					xwtpList.add(xwxq);
				}
				return xwtpList;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			} finally {
				DBManager.closeAll(conn, st, rs);
			}
		}
}
